import React from 'react';
import { Form, Tag, Table } from 'antd';
import { FormLayout } from '../../components';

const TYPE_MAP = {
    1: '工作结果',
    2: '工作时效性',
    3: '工作饱和度'
};

const STANDARD_MAP = {
    1: text => `任务结果不通过不超过 ${text} 次`,
    2: text => `任务完成逾期不超过 ${text} 次`,
    3: text => `高于部门平均饱和度(${text}%)`
};

const EXECUTE_INFO_MAP = {
    1: text => `${text} 次`,
    2: text => `${text} 次`,
    3: text => `饱和度${text}%`
};

const TAG_MAP = {
    0: <Tag color="red">不合格</Tag>,
    1: <Tag color="green">合格</Tag>
};

const TEXT_MAP = {
    不合格: (
        <Tag color="red" style={{ border: 'none', background: 'none' }}>
            不合格
        </Tag>
    ),
    合格: (
        <Tag color="green" style={{ border: 'none', background: 'none' }}>
            合格
        </Tag>
    )
};

/**
 * 任务情况
 *
 * @param {*} { data = {},type：month，quarter，week }
 */
export default function AssessTask({ data = {}, type = 'week' }) {
    const { taskResults = {}, taskResult = '', startTime, endTime } = data;
    const { requirementsCount = 0, detail: dataSource = [] } = taskResults;
    const time = endTime && startTime ? `${startTime} ~ ${endTime}` : '';

    const columns = [
        {
            title: '名称',
            dataIndex: 'type',
            render(text) {
                return TYPE_MAP[text];
            }
        },
        {
            title: '考核标准',
            dataIndex: `${type}Value`,
            render(text, row) {
                return STANDARD_MAP[row.type] && STANDARD_MAP[row.type](text);
            }
        },
        {
            title: '执行情况',
            dataIndex: 'executeInfo',
            render(text, row) {
                return EXECUTE_INFO_MAP[row.type] && EXECUTE_INFO_MAP[row.type](text);
            }
        },
        {
            title: '考核结果',
            dataIndex: 'executeResult',
            render(text) {
                return TEXT_MAP[text] || '-';
            }
        }
    ];

    return (
        <div style={{ width: 900 }}>
            <FormLayout type="full">
                <Form.Item label="考核结果">{taskResult !== '' && TAG_MAP[taskResult]}</Form.Item>
            </FormLayout>
            <FormLayout type="full">
                <Form.Item label="任务要求">
                    试用期新员工被分配任务存在
                    <span style={{ padding: 8, color: 'red' }}>{requirementsCount}</span>
                    项子任务考核不合格时，则整体考核视为不合格
                </Form.Item>
            </FormLayout>
            <FormLayout type="full">
                <Form.Item label="任务内容">
                    {time && <div>新员工 {time} 的工作任务情况</div>}
                    <Table rowKey="type" bordered columns={columns} dataSource={dataSource} pagination={false} />
                </Form.Item>
            </FormLayout>
        </div>
    );
}
